#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <string>
#include <vector>
class Solution {
public:
    int numDecodings(string s) {
        int n = s.size();
        vector<int> dp(n);
        if (s[0] != '0')
            dp[0] = 1;
        if (n == 1)
            return dp[0];
        if (dp[0])
        {
            int num = (s[0] - '0') * 10 + s[1] - '0';
            if (s[1] != '0')
                dp[1]++;
            if (num >= 10 && num <= 26)
                dp[1]++;
        }
        for (int i = 2; i < n; i++)
        {
            if (s[i] != '0')
                dp[i] += dp[i - 1];
            int num = (s[i - 1] - '0') * 10 + s[i] - '0';
            if (num >= 10 && num <= 26)
                dp[i] += dp[i - 2];
            //else
                //dp[i] = 0;
        }
        return dp[n - 1];
    }
};
int main()
{
    Solution s;
    int ret = s.numDecodings(string("10"));
    return 0;
}

class Solution {
public:
    int numDecodings(string s) {
        int n = s.size();
        vector<int> dp(n + 1);
        dp[0] = 1;
        if (s[0] != '0')
            dp[1] = 1;
        if (n == 1)
            return dp[1];
        for (int i = 2; i <= n; i++)
        {
            if (s[i - 1] != '0')
                dp[i] += dp[i - 1];
            int num = (s[i - 2] - '0') * 10 + s[i - 1] - '0';
            if (num >= 10 && num <= 26)
                dp[i] += dp[i - 2];
            //else
                //dp[i] = 0;
        }
        return dp[n];
    }
};